<script type="text/javascript">
	$(document).ready(function(){

		$('#petition').dataTable();
		
	});

	function verifyPetition(id){
		var task = "verify";
		//alert(id);

			$.post('processPetition.php',{task: task, petition_id: id}, function(data) {
					window.location.href="index.php?pages=finance";
			});

	}

	function cancelPetition(id){
		var task = "cancel";
		//alert(id);

		$('<div>').dialog2({
			autoOpen: true,
			title: "ยกเลิกฎีกา",
			content: "dlgCancel_peti.php?petition_id=" + id,
			id: "modal-cancelPeti"
		});

	}

	function approvedPetition(id){
		var task = "approved";

		$('<div>').dialog2({
			autoOpen: true,
			title: "อนุมัติ",
			content: "dlgDate.php?petition_id=" + id + "&task=" + task,
			id: "modal-dlgDate"
		});
		/*
			$.post('processPetition.php',{task: task, petition_id: id}, function(data) {
					window.location.href="index.php?pages=finance";
			});

		*/

	}
	function disapprovalPetition(id){
		var task = "disapproval";

			$.post('processPetition.php',{task: task, petition_id: id}, function(data) {
					window.location.href="index.php?pages=finance";
			});

	}

</script>

<?php
	//echo "finance.php"
	require_once("includes/connect.php");

	$db = new myDBS;
	$db->selectDB("account");
	//$where = "petition_id = '$petition_id'";
	$sql ="SELECT tbl_petition.*, pp_check_job.proID, projectName, amount, instalment FROM tbl_petition, pp_check_job WHERE tbl_petition.ppID = pp_check_job.ppID";
	$result = $db->runSQL($sql);


?>
	<table id="petition" class="table table-striped table-bordered" width="100%" >
		<caption><br></caption>
		<thead>
			<tr>
				<th>#</th>
				<th>เลขที่โครงการ</th>
				<th>ชื่อโครงการ</th>
				<th>งบประมาณ</th>
				<th>ยอดเบิกจ่าย</th>
				<th>งวดที่</th>
				<th>วันที่เบิกฏีกา</th>
				<th>รายละเอียดเพิ่มเติม</th>
				<th>ตรวจรับฏีกา</th>
				<th>อนุมัติ</th>
			</tr>
		</thead>
		<tbody>
			<?php
				$i=0;
				while ( $rows = $db->fetch_object ( $result )){
					$i++;
			?>
			<tr>
				<td><?php echo $i; ?></td>
				<td>
				<?php 
						if($rows->veri_status == "Not Verify") {
				?>
				<a href="index.php?pages=sumPetition1&petition_id=<?php echo $rows->petition_id; ?>" target="_blank"><?php echo $rows->proID; ?></a>
				<?php
						} else {
							echo $rows->proID;
						}
				?>
					
				</td>
				<td><?php echo $rows->projectName; ?></td>
				<td><?php echo number_format($rows->amount); ?></td>
				<td><?php echo number_format($rows->inpNet); ?></td>
				<td><?php echo $rows->instalment; ?></td>
				<td><?php echo $rows->date_create; ?></td>
				<td>
					<a href="#" id="info_<?php echo $rows->ppID; ?>"><i class="icon-list"></i>&nbsp;ดู</a>
				</td>
	 			<td>
					<?php 
						if($rows->veri_status <> "Not Verify") {
							echo $rows->veri_status;
						} else {
					?>
					<a href="javascript:verifyPetition('<?php echo $rows->petition_id; ?>')" data-toggle="tooltip" title="ผ่าน"><i class="icon-ok"></i></a>&nbsp;<big>|</big>&nbsp;<a href="javascript:cancelPetition('<?php echo $rows->petition_id; ?>')" data-toggle="tooltip" title="ไม่ผ่าน"><i class="icon-remove"></i></a>
					<?php } ?>
				</td>
				<td>
					<?php 
					if ($rows->veri_status == "Pass") {
						if($rows->approved_status <> "Not Approve") {
							echo $rows->approved_status;
						} else {
					?>
						<a href="javascript:approvedPetition('<?php echo $rows->petition_id; ?>')" data-toggle="tooltip" title="อนุมัติ"><i class="icon-thumbs-up"></i></a>&nbsp;<big>|</big>&nbsp;<a href="javascript:disapprovalPetition('<?php echo $rows->petition_id; ?>')" data-toggle="tooltip" title="ไม่อนุมัติ"><i class="icon-thumbs-down"></i></a>

						
					<?php 
						}
					}
					?>
				</td>
			</tr>
			<?php
					
				}
			?>

		</tbody>


	</table>
